﻿using System;
using System.Collections.Generic;
using FirstFloor.Documents.IO;

namespace FirstFloor.Documents.Pdf
{
    /// <summary>
    /// Provides information about a parsed PDF document.
    /// </summary>
    internal class PdfDocument
        : IDisposable
    {
        internal PdfDocument(PdfParser owner)
        {
            this.Owner = owner;
        }
        /// <summary>
        /// Gets the parser this document originates from.
        /// </summary>
        /// <value>The owner.</value>
        public PdfParser Owner { get; private set; }
        /// <summary>
        /// Gets the version of the PDF document.
        /// </summary>
        /// <value>The PDF version.</value>
        public Version PdfVersion { get; internal set; }
        /// <summary>
        /// Gets the identifier that uniquely identifies the PDF document.
        /// </summary>
        /// <value>The file identifier.</value>
        public byte[][] FileIdentifier { get; internal set; }
        /// <summary>
        /// Gets the number of pages found in the PDF document.
        /// </summary>
        /// <value>The page count.</value>
        public int PageCount { get; internal set; }

        /// <summary>
        /// Gets the XAML of specified page.
        /// </summary>
        /// <param name="pageNumber">The page number.</param>
        /// <param name="settings">The settings.</param>
        /// <returns></returns>
        /// <remarks>
        /// Page numbers are 1-based.
        /// </remarks>
        public string GetPageXaml(int pageNumber, LoadSettings settings)
        {
            if (pageNumber < 1 || pageNumber > this.PageCount) {
                throw new ArgumentOutOfRangeException("pageNumber");
            }

            // note page caching is done at XpsDocument level (FixedPageCache)

            return this.Owner.ParsePage(pageNumber, settings);
        }

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            this.Owner.Dispose();
        }
    }
}
